package demo;

import java.util.Stack;

/**
 *    用栈实现队列
 */
class Solution29 {
	private Stack<Integer> stackIn = new Stack<>();
	private Stack<Integer> stackOut = new Stack<>();
	public Solution29() {
	}

	public void push(int x) {
		stackIn.push(x);
	}

	public int pop() {
		if (stackOut.isEmpty()) {
			while (!stackIn.isEmpty()) {
				stackOut.push(stackIn.pop());
			}
		}
		return stackOut.pop();
	}

	public int peek() {
		if (stackOut.isEmpty()) {
			while (!stackIn.isEmpty()) {
				stackOut.push(stackIn.pop());
			}
		}
		return stackOut.peek();
	}

	public boolean empty() {
		return stackIn.isEmpty() && stackOut.isEmpty();
	}
}

